// i.d(t, { t: () => ToolsData })

import Data from "../object/Data"
import ObservableValue, { createObVal } from "../observer/observable.value"
import ObservableMap, { createMap } from "../observer/observable.map"
import { toolAccess } from "../enum/tool.enum"
import panelLayoutEnum from "../enum/panelLayout.enum"
import toolConst from "../constant/tool.const"
import Tool from "../object/Tool"
export default class ToolsData extends Data {
  tools: ObservableMap<Tool>
  toolsLoadedObservable: ObservableValue<boolean>
  openAssetObservable: ObservableValue<any>
  activeToolOpen: boolean
  activeToolNameObservable: ObservableValue<string>
  openModalObservable: ObservableValue<any>
  toolAccessObservable: ObservableValue<string>
  panelLayoutObservable: ObservableValue<string>
  panelCollapsedObservable: ObservableValue<boolean>
  constructor() {
    super()
    this.name = "tools-data"
    this.tools = createMap()
    this.toolsLoadedObservable = createObVal(!1)
    this.openAssetObservable = createObVal(null)
    this.activeToolOpen = !1
    this.activeToolNameObservable = createObVal(null)
    this.openModalObservable = createObVal(null)
    this.toolAccessObservable = createObVal(toolAccess.SCENE)
    this.panelLayoutObservable = createObVal(toolConst.isBigWin() ? panelLayoutEnum.NORMAL : panelLayoutEnum.NARROW)
    this.panelCollapsedObservable = createObVal(!1)
  }
  addTools(e: any[]) {
    e.forEach(e => {
      this.addTool(e)
    })
    this.toolsLoadedObservable.value = !0
  }
  iterate(e) {
    for (const t of this.tools) e(t)
  }
  get toolsMap() {
    return this.tools
  }
  getTool(e: string) {
    return this.tools.get(e)
  }
  addTool(e: Tool) {
    this.tools.set(e.id, e)
  }
  removeTool(e: string) {
    this.tools.delete(e)
  }
  removeAllTools() {
    this.tools.clear()
    this.toolsLoadedObservable.value = !1
  }
  get openAsset() {
    return this.openAssetObservable.value
  }
  setOpenAsset(e) {
    this.openAssetObservable.value = e
  }
  onOpenAssetChanged(e) {
    return this.openAssetObservable.onChanged(e)
  }
  getActiveTool() {
    return this.activeToolName ? this.getTool(this.activeToolName) : null
  }
  get activeToolName() {
    return this.activeToolNameObservable.value
  }
  get toolOpen() {
    return this.activeToolOpen
  }
  setActiveTool(e, t = !1) {
    e === this.activeToolNameObservable.value && this.activeToolOpen !== t
      ? ((this.activeToolOpen = t), this.activeToolNameObservable.setDirty())
      : ((this.activeToolOpen = t), (this.activeToolNameObservable.value = e))
  }
  onToolChanged(e) {
    return this.activeToolNameObservable.onChanged(e)
  }
  get openModal() {
    return this.openModalObservable.value
  }
  setOpenModal(e) {
    this.openModalObservable.value = e
  }
  onOpenModalChanged(e) {
    return this.openModalObservable.onChanged(e)
  }
  onToolsLoadedChanged(e) {
    return this.toolsLoadedObservable.onChanged(e)
  }
  get toolsLoaded() {
    return this.toolsLoadedObservable.value
  }
  get toolAccess() {
    return this.toolAccessObservable.value
  }
  setToolAccess(e) {
    this.toolAccessObservable.value = e
  }
  onToolAssetAccessChanged(e) {
    return this.toolAccessObservable.onChanged(e)
  }
  isPanelOpen() {
    return this.toolPanelLayout === panelLayoutEnum.SIDE_PANEL || this.toolPanelLayout === panelLayoutEnum.BOTTOM_PANEL
  }
  isPanelCollapsedToBottom() {
    return this.toolPanelLayout === panelLayoutEnum.BOTTOM_PANEL && this.panelCollapsed
  }
  setToolPanelLayout(e) {
    this.panelLayoutObservable.value = e
  }
  get toolPanelLayout() {
    return this.panelLayoutObservable.value
  }
  onToolPanelLayoutChanged(e) {
    return this.panelLayoutObservable.onChanged(e)
  }
  onPanelCollapsedChanged(e) {
    return this.panelCollapsedObservable.onChanged(e)
  }
  setPanelCollapsed(e) {
    this.panelCollapsedObservable.value = e
  }
  get panelCollapsed() {
    return this.panelCollapsedObservable.value
  }
}
